package cn.hrlly.tao2shou.presenter;

import android.content.Context;

import cn.hrlly.tao2shou.R;
import cn.hrlly.tao2shou.biz.AlterUserInfoBiz;
import cn.hrlly.tao2shou.biz.AlterUserInfoBizImpl;
import cn.hrlly.tao2shou.domain.User;
import cn.hrlly.tao2shou.listener.OnAlterUserInfoListener;
import cn.hrlly.tao2shou.view.view_interface.AlterUserInfoView;

/**
 * User: gengliang
 * Date: 2016-01-31
 * Time: 19:56
 */

public class AlterUserInfoPresenterImpl implements AlterUserInfoPresenter,OnAlterUserInfoListener {

    private AlterUserInfoBiz alterUserInfoBiz;
    private AlterUserInfoView alterUserInfoView;

    public AlterUserInfoPresenterImpl(AlterUserInfoView alterUserInfoView,Context context) {
        this.alterUserInfoView = alterUserInfoView;
        this.alterUserInfoBiz=new AlterUserInfoBizImpl(this,context);
    }

    @Override
    public void alterUserInfo() {
        User user=new User();
        user.setNickname(alterUserInfoView.getNickname());
        user.setGender(alterUserInfoView.getGender());
        user.setSchool(alterUserInfoView.getSchool());
        alterUserInfoBiz.alterUserInfo(user,alterUserInfoView.getHeadPortrait());
    }

    @Override
    public void closeDataBase() {
        alterUserInfoBiz.closeDataBase();
    }

    @Override
    public void alterUserInfoSucc(User user) {
        alterUserInfoView.showMessage(R.string.alter_user_info_success);
        alterUserInfoView.finishActivity();

        //将用户信息保存数据库
        alterUserInfoBiz.saveUserInfo(user);
    }

    @Override
    public void alterUserInfoFail(String errorMessage) {
        alterUserInfoView.showMessage(errorMessage);
    }

    @Override
    public void alterUserInfoFail(int errorMessage) {

    }
}
